package easybooking.report;

import java.util.Vector;

/**

 * A <code>ReportWriter</code>, which is formatting reports by using Plain text. The result in the
 * desired format is stored in the variable <code>reportText</code>
 * and can be readed out by calling the processing operation
 * <code>getReportText()</code>.
 *
 * @author Hakan Keles
 */
public class PlainTextReportWriter extends ReportWriter {

    /**
     * This variable is allocated with the result of the conversion.
     */
    private String reportText = "";

    /**
     * Reset the variable <code>reportText</code>.
     */
    public void resetReportText() {
        this.reportText = "";
    }

    /**
     * Produce header-text.
     * @return text
     */
    public String getHeader() {
        return "";
    }

    /**
     * Produce trailer-text.
     * @return text
     */
    public String getTrailer() {
        return "___________________________________________";
    }

    /**
     * Process the passed report und deposit it in the desired format. Later a read-out of the report
     * is possible with method <code>getReportText()</code>.
     *
     * @param f the passed report
     */
    public void process(AllFlightsOfCustomerReport f) {
        this.resetReportText();
        StringBuffer result = new StringBuffer();
        result.append("*** " + f.getTitle() + " ***\n\n");
        result.append(f.getHeader() + "\n");
        result.append("Erstellt am: " + f.getDateTime().toString() + "\n\n");
        Vector<Row> rows = f.getRows();
        for (Row row : rows) {
            for (int k = 0; k < row.getNumColumns(); k++) {
                result.append(row.getColumnAt(k) + "\t ; \t");
            }
            result.append("\n");
        }
        result.append("\n");
        this.reportText = result.toString();
    }

    /**
     * Process the passed report und deposit it in the desired format. Later a read-out of the report
     * is possible with method <code>getReportText()</code>.
     *
     * @param fca the passed report
     */
    public void process(AllFlightsOfCustomerWithAirlineReport fca) {
        this.resetReportText();
        StringBuffer result = new StringBuffer();
        result.append("*** " + fca.getTitle() + " ***\n\n");
        result.append(fca.getHeader() + "\n");
        result.append("Erstellt am: " + fca.getDateTime().toString() + "\n\n");
        Vector<Row> rows = fca.getRows();
        for (Row row : rows) {
            for (int k = 0; k < row.getNumColumns(); k++) {
                result.append(row.getColumnAt(k) + "\t ; \t");
            }
            result.append("\n");
        }
        result.append("\n");
        this.reportText = result.toString();
    }

    /**
     * Process the passed report und deposit it in the desired format. Later a read-out of the report
     * is possible with method <code>getReportText()</code>.
     *
     * @param fs the passed report
     */
    public void process(FlightSeatingReport fs) {
        this.resetReportText();
        StringBuffer result = new StringBuffer();
        result.append("*** " + fs.getTitle() + " ***\n\n");
        result.append(fs.getHeader() + "\n");
        result.append("Erstellt am: " + fs.getDateTime().toString() + "\n\n");
        Vector<Row> rows = fs.getRows();
        for (Row row : rows) {
            for (int k = 0; k < row.getNumColumns(); k++) {
                result.append(row.getColumnAt(k) + "\t ; \t");
            }
            result.append("\n");
        }
        result.append("\n");
        this.reportText = result.toString();
    }

    /**
     * Read-out the result of the last called processing method..
     *
     * @return String with a simple text
     */
    public String getReportText() {
        return this.getHeader() + this.reportText + this.getTrailer();
    }
}


